local skill = fk.CreateSkill{
  name = "tea__zaobing",
}
---@type TrigSkelSpec<TrigFunc>
local zaobing = {
  anim_type = "offensive",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player.room.current then
      if target ~= player and not target.dead then
        local events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
          local use = e.data
          return table.contains(use.tos, player) and use.card.type == Card.TypeTrick
        end, Player.HistoryTurn)
        return player:canUseTo(Fk:cloneCard("slash"), target, {
          bypass_distances = true
        }) and #events > 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, skill.name, "offensive")
		player:broadcastSkillInvoke(skill.name, table.random({1, 2}))
    local current = room.current
    local card = Fk:cloneCard("slash")
    local use = { ---@type UseCardDataSpec
      from = player,
      tos = { current },
      card = card,
      extraUse = true,
      extra_data = {is_zaobing = {player, current}}
    }
    room:useCard(use)
  end,
}
---@type TrigSkelSpec<TrigFunc>
local zaobing_re = {
  can_refresh = function(self, event, target, player, data)
    if data.card and player == target then
      if data.card.trueName == "slash" then
        if (data.extra_data or {}).is_zaobing then
          local to = data.extra_data.is_zaobing[2]
          return ((data.damageDealt or {})[to] or 0) == 0
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local from = data.extra_data.is_zaobing[1]
    local to = data.extra_data.is_zaobing[2]
    if room:askToSkillInvoke(to, {skill_name = self.name, prompt = "#tea__zaobing-invoke:"..from.id}) then
      room:notifySkillInvoked(player, self.name, "negative")
      player:broadcastSkillInvoke(skill.name, 3)
      if #from:getCardIds("he") <= 2 then
        room:throwCard(from:getCardIds("he"), skill.name, from, to)
      else
        local cids = room:askToChooseCards(to, {
          target = from,
          min = 2,
          max = 2,
          skill_name = skill.name,
          flag = "he",
          prompt = "#tea__zaobing-choose",
        })
        room:throwCard(cids, self.name, from, to)
      end
    end
  end,
}
skill:addEffect(fk.TurnEnd, zaobing)
skill:addEffect(fk.CardUseFinished, zaobing_re)
return skill